package com.graph.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.graph.base.CommunityFinder;

public class transCommunity {
	static List<ArrayList<Integer>> coummunity=new ArrayList<ArrayList<Integer>>(20);
	public static void main(String[] args) {
		for (int i = 0; i < 50; i++) {
			coummunity.add(new ArrayList<Integer>());
		}
		read(".\\Data\\LFR\\","community1000.dat");
		for (ArrayList<Integer> com : coummunity) {
			if(com.size()==0){
				continue;
			}
			for (int i = 0; i < com.size(); i++) {
				System.out.print(com.get(i));
				if(i+1<com.size()){
				System.out.print(",");
				}
			}
			System.out.print(";");
		}

	}
	private static ArrayList<String> CommunityData;
	static void read(String path,String inputFileName){
		  File file = new File(path+inputFileName);
			if (file.exists() && file.isFile()) {
				try {
					InputStreamReader read = new InputStreamReader(
							new FileInputStream(file), "UTF-8");
					BufferedReader bufferreader = new BufferedReader(read);
					String LineTxt = null;
					CommunityData = new ArrayList<String>();
					try {
						while ((LineTxt = bufferreader.readLine()) != null) {
							CommunityData.add(LineTxt);
						}
						read.close();
					} catch (IOException e) {
						e.printStackTrace();
						System.out.println("读取数据错误");
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
					System.out.println("读取数据错误");
				} catch (FileNotFoundException e) {
					e.printStackTrace();
					System.out.println("读取数据错误");
				}
			}
			if(CommunityData!=null){
              for (String string : CommunityData) {
            		String[] data2 = string.split("\t");
            		Integer i=Integer.valueOf(data2[1]);
            		Integer size=coummunity.size();
            		Integer cha=i-size;
            		ArrayList<Integer> coumm=coummunity.get(i-1);
            		coumm.add(Integer.parseInt(data2[0]));
            		System.out.print(data2[0]+",");
			}
              System.out.println();
			}
			
			
		
	}

}
